# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=base-compat-batteries
pkgname=haskell-base-compat-batteries
pkgver=0.12.2
pkgrel=66
pkgdesc="base-compat with extra batteries"
url="https://hackage.haskell.org/package/base-compat-batteries"
license=('MIT')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-base-compat')
makedepends=('ghc')
checkdepends=('haskell-hspec' 'haskell-hspec-discover' 'haskell-quickcheck')
source=(https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz)
sha512sums=('655e25ef307feacdf2e6e2670700c4f46acf0702776bb5eee609472d6b7f87f6118e0b652d44a8daef390e075ecff9b9000839468d4716fb8864495d9f19503a')

build() {
    cd $_hkgname-$pkgver

    if (( CHECKFUNC )); then
        _opts=('--enable-tests')
    else
        _opts=('--disable-tests')
    fi

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname "${_opts[@]}" \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $_hkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $_hkgname-$pkgver
    
    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
